package com.jxb.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

/**
 * @author jinxb
 * date     : 2021/5/7
 * desc     :
 */
public abstract class BaseDialog extends Dialog {

    protected final Context context;

    public BaseDialog(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(getContentView());
        setCanceledOnTouchOutside(false);
        Window window = getWindow();
        window.getDecorView().setPadding(0, 0, 0, 0);
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setGravity(Gravity.CENTER);
        layoutParams.width = (int) (displayMetrics.widthPixels * 1);
        window.setAttributes(layoutParams);
        initViews();
        initListeners();
    }

    protected abstract int getContentView();

    protected abstract void initListeners();

    protected abstract void initViews();

    public interface OnBtnClickListener {
        void onClick();
    }

    public interface OnInputBtnClickListener {
        void onClick(String info);
    }

}
